package com.tb.controller;

import com.tb.dubbo.IorderStatusService;
import com.tb.pojo.User;
import com.tb.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @创建人 lxq
 * @创建时间 2019/1/14
 * @描述 根据用户id查询订单待付款数量，待收货数量，待评价数量
 */
@RestController
public class OrderStatusController {
    @Autowired
    private IorderStatusService orderStatusService;
    /**
     * @api {GET} /orderStatus 待付款,待收货,待评价
     * @apiDescription 根据用户id查询订单待付款数量，待收货数量，待评价数量
     *  <br/><span style="color:#012456"><b>作者:刘献强</b></span>
     * @apiGroup Order API
     *
     *
     * @apiVersion 1.0.0
     *
     * @apiSuccess  {int} code 返回状态码
     *
     * @apiSuccess  {string} msg 返回错误信息 999：登陆超时
     * @apiSuccess  {Object} data
     *
     * @apiSuccessExample {json} 正确返回值:
     *   {
     *     "code": 0,
     *     "msg": "",
     *     "data": {
     *         "DFK": 5,  //待付款
     *         "DSH": 1,  //待收货
     *         "DPJ": 6   //待评价
     *         "userName": "zhangsan",//用户名
     *     }
     * }
     *
     * @apiErrorExample {json} 错误返回值:
     *     {
     * 	"code": 999,
     * 	"msg": "登陆超时",
     * 	"data": null
     * }
     *
     * @apiSampleRequest  /orderStatus
     */
    @GetMapping(value = "/orderStatus")
    public Msg getOrderStatus(HttpSession session){

        try {
            User user= (User) session.getAttribute("User");
            String id=user.getUserId();
            String userName=user.getUserName();

            Map<String, Object> map = orderStatusService.getOrderStatus(id);
            map.put("userName",userName);

            return Msg.success(map);

        }catch (Exception e){
            return Msg.error(999,"登陆超时");
        }

    }

}
